package com.example.demo.listnode;

import com.example.demo.model.ListNode;

/**
 * https://leetcode.cn/problems/shan-chu-lian-biao-de-jie-dian-lcof/description/
 */
public class DeleteNode {

    public ListNode deleteNode(ListNode head, int val) {
        if (head == null) return null;
        if (head.val == val) return head.next;

        ListNode pre = head;
        ListNode cur = head.next;
        while (cur != null && cur.val != val) {
            pre = cur;
            cur = cur.next;
        }
        if (cur != null) pre.next = cur.next;
        return head;
    }
}
